unit UI;

interface

uses
  Head,
  sysutils,
  Engine,
  PakFile,
  PicFile,
  graphics,
  LConvEncoding;

type
  TUI = class
  const
    UIPakFile = 'UI.dat';
    mousefile = 'mouse.png';
  public
    UIEngine: PEngine;
    UIPicFile: TPicFile;
    Destructor Destroy;
    function Initial(PUIEngine: PEngine): integer;
    function Release: integer;
    function DrawUI: integer;
    function DrawMouse(x, y: integer): integer;
    function DrawMouseToBuf(x, y: integer): integer;
  end;

implementation

Destructor TUI.Destroy;
begin
  Release;
  inherited Destroy;
end;

function TUI.Initial(PUIEngine: PEngine): integer;
begin
  UIEngine := PUIEngine;
  UIPicFile := TPicFile.Create;
  UIPicFile.PicEngine := UIEngine;
  UIPicFile.filenum := 1;
  setlength(UIPicFile.MPCFile, UIPicFile.filenum);
  UIPicFile.MPCFile[0].Filename := MouseFile;
  UIPicFile.MPCFile[0].FileID := UIPicFile.Pak.HashFileName(PAnsichar(StrtoAnsi(UIPicFile.MPCFile[0].Filename)));
  UIPicFile.MPCFile[0].Pictype := IMG;
  setlength(UIPicFile.MPCFile[0].MPCpic, 1);
  UIPicFile.MPCFile[0].MPCpic[0].PIC := TPicture.create;
  UIPicFile.MPCFile[0].MPCpic[0].PIC.LoadFromFile(UIPicFile.MPCFile[0].Filename);
  result := 0;
end;

function TUI.DrawUI: integer;
begin
  //
end;

function TUI.DrawMouse(x, y: integer): integer;
begin
  result := DrawMouseToBuf(x, y);
end;

function TUI.DrawMouseToBuf(x, y: integer): integer;
begin
  if (x >= 0) and (y >= 0) then
  begin
    //UIEngine.drawPICtoBuf('mouse.png', x, y);
    UIEngine.drawPICtoBuf(@(UIPicFile.MPCFile[0].MPCpic[0].PIC), x, y);
  end;
  result := 0;
end;

function TUI.Release: integer;
begin
  UIPicFile.Release;
  UIPicFile.Free;
  result := 0;
end;

end.
